package com.java.tutorials.jdk7.fileoperation;

import com.java.tutorials.Constants;

import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

/**
 * Created by xuzhike on 2016/1/25.
 * http://www.java2s.com/Code/Java/JDK-7/WritingtoafileusingtheBufferedWriterclass.htm\
 * Writing to a file using the BufferedWriter class
 */
public class WritingtoafileusingtheBufferedWriterclass {
    public static void main(String[] args) throws IOException {
        String newName = "asdf";
        Path file = Paths.get(Constants.TEST_PATH+"/test.txt");//把新内容追加到该文件后面
        try (BufferedWriter writer = Files.newBufferedWriter(file, Charset.defaultCharset(), StandardOpenOption.APPEND)) {
            writer.newLine();
            writer.write(newName, 0, newName.length());
        }

    }
}
